package com.ali.controller;

import com.ali.common.Response;
import com.ali.dto.OrderInfo;
import com.ali.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 下单并支付
     */
    @PostMapping(value = "/add/pay")
    public Response<String> addOrderAndPay(@RequestBody Map<String, Object> param) {
        log.info("addOrderAndPay：" + param);
        orderService.addOrderAndPay(param);
        return Response.success("成功增加记录");
    }

    /**
     * 修改订单
     */
    @PostMapping(value = "/update")
    public Response<String> update(@RequestBody Map<String, Object> param) {
        log.info("update：" + param);
        orderService.update(param);
        return Response.success("成功修改记录");
    }

    /**
     * 删除订单
     */
    @PostMapping(value = "/delete")
    public Response<String> delete(@RequestBody Map<String, Object> param) {
        log.info("delete：" + param);
        orderService.delete(param);
        return Response.success("成功删除记录");
    }

    /**
     * 查询所有订单
     */
    @GetMapping(value = "/all")
    public Response<List<OrderInfo>> getAll(@RequestParam Map<String, Object> param) {
        log.info("getAll：" + param);
        List<OrderInfo> orderInfos = orderService.getAll(param);
        return Response.success(orderInfos);
    }

    /**
     * 查询单个订单
     */
    @GetMapping(value = "/id")
    public Response<OrderInfo> getById(@RequestParam Map<String, Object> param) {
        log.info("getById：" + param);
        OrderInfo orderInfo = orderService.getById(param);
        return Response.success(orderInfo);
    }
}